
#include <main.h>
#include "document_manager.h"
#include "uimanager.h"




struct _MainWndPrivate {
	DocumentManager* document_manager;
	UIManager* ui_manager;
};

#define MAIN_WND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MAIN_WND, MainWndPrivate))
enum  {
	MAIN_WND_DUMMY_PROPERTY
};
static void main_wnd_real_on_file_new_actived (MainWnd* self);
static void main_wnd_real_on_file_quit_actived (MainWnd* self);
static gboolean main_wnd_real_on_delete_event (MainWnd* self);
static void _gtk_main_quit_gtk_object_destroy (MainWnd* _sender, gpointer self);
static void _main_wnd_on_file_new_actived_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_open_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_save_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_save_as_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_save_all_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_close_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void __lambda2 (MainWnd* self);
static void ___lambda2_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _main_wnd_on_file_quit_actived_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_undo_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_redo_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_cut_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_copy_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_paste_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_delete_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_select_all_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_search_in_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_goto_next_found_match_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_goto_prev_found_match_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_replace_in_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static void _document_manager_goto_line_current_gtk_action_activate (GtkAction* _sender, gpointer self);
static gboolean _main_wnd_on_delete_event_gtk_widget_delete_event (MainWnd* _sender, const GdkEvent* event, gpointer self);
static GObject * main_wnd_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gpointer main_wnd_parent_class = NULL;
static void main_wnd_finalize (GObject* obj);



static void main_wnd_real_on_file_new_actived (MainWnd* self) {
	g_return_if_fail (self != NULL);
	document_manager_create (self->priv->document_manager, NULL);
}


void main_wnd_on_file_new_actived (MainWnd* self) {
	MAIN_WND_GET_CLASS (self)->on_file_new_actived (self);
}


static void main_wnd_real_on_file_quit_actived (MainWnd* self) {
	gboolean _tmp0;
	g_return_if_fail (self != NULL);
	if ((_tmp0 = document_manager_close_all (self->priv->document_manager), (_tmp0 == NULL) ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL)), _tmp0)) {
		gtk_object_destroy ((GtkObject*) self);
	}
}


void main_wnd_on_file_quit_actived (MainWnd* self) {
	MAIN_WND_GET_CLASS (self)->on_file_quit_actived (self);
}


static gboolean main_wnd_real_on_delete_event (MainWnd* self) {
	g_return_val_if_fail (self != NULL, FALSE);
	return (!document_manager_close_all (self->priv->document_manager));
}


gboolean main_wnd_on_delete_event (MainWnd* self) {
	return MAIN_WND_GET_CLASS (self)->on_delete_event (self);
}


gint main_wnd_main (char** args, int args_length1) {
	MainWnd* wnd;
	gint _tmp0;
	gtk_init (&args_length1, &args);
	wnd = g_object_ref_sink (main_wnd_new ());
	gtk_widget_show_all ((GtkWidget*) wnd);
	if (args_length1 > 1) {
		{
			gint i;
			i = 1;
			for (; i < args_length1; (i = i + 1)) {
				/*Otwieramy pliki podane jako argument funkcji...*/
				document_manager_create (document_manager_get_instance (), args[i]);
			}
		}
	} else {
		document_manager_create (document_manager_get_instance (), NULL);
	}
	gtk_main ();
	return (_tmp0 = 0, (wnd == NULL) ? NULL : (wnd = (g_object_unref (wnd), NULL)), _tmp0);
}


int main (int argc, char ** argv) {
	g_type_init ();
	return main_wnd_main (argv, argc);
}


MainWnd* main_wnd_construct (GType object_type) {
	MainWnd * self;
	self = g_object_newv (object_type, 0, NULL);
	return self;
}


MainWnd* main_wnd_new (void) {
	return main_wnd_construct (TYPE_MAIN_WND);
}


static void _gtk_main_quit_gtk_object_destroy (MainWnd* _sender, gpointer self) {
	gtk_main_quit ();
}


static void _main_wnd_on_file_new_actived_gtk_action_activate (GtkAction* _sender, gpointer self) {
	main_wnd_on_file_new_actived (self);
}


static void _document_manager_open_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_open (self);
}


static void _document_manager_save_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_save_current (self);
}


static void _document_manager_save_as_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_save_as_current (self);
}


static void _document_manager_save_all_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_save_all (self);
}


static void _document_manager_close_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_close_current (self);
}


static void __lambda2 (MainWnd* self) {
	document_manager_close_all (self->priv->document_manager);
}


static void ___lambda2_gtk_action_activate (GtkAction* _sender, gpointer self) {
	__lambda2 (self);
}


static void _main_wnd_on_file_quit_actived_gtk_action_activate (GtkAction* _sender, gpointer self) {
	main_wnd_on_file_quit_actived (self);
}


static void _document_manager_undo_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_undo_current (self);
}


static void _document_manager_redo_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_redo_current (self);
}


static void _document_manager_cut_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_cut_current (self);
}


static void _document_manager_copy_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_copy_current (self);
}


static void _document_manager_paste_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_paste_current (self);
}


static void _document_manager_delete_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_delete_current (self);
}


static void _document_manager_select_all_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_select_all_current (self);
}


static void _document_manager_search_in_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_search_in_current (self);
}


static void _document_manager_goto_next_found_match_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_goto_next_found_match_current (self);
}


static void _document_manager_goto_prev_found_match_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_goto_prev_found_match_current (self);
}


static void _document_manager_replace_in_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_replace_in_current (self);
}


static void _document_manager_goto_line_current_gtk_action_activate (GtkAction* _sender, gpointer self) {
	document_manager_goto_line_current (self);
}


static gboolean _main_wnd_on_delete_event_gtk_widget_delete_event (MainWnd* _sender, const GdkEvent* event, gpointer self) {
	return main_wnd_on_delete_event (self);
}


static GObject * main_wnd_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	MainWndClass * klass;
	GObjectClass * parent_class;
	MainWnd * self;
	klass = MAIN_WND_CLASS (g_type_class_peek (TYPE_MAIN_WND));
	parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = MAIN_WND (obj);
	{
		GtkVBox* vbox;
		GtkWidget* _tmp1;
		GtkWidget* menubar;
		gtk_window_set_title ((GtkWindow*) self, "FootEdit");
		gtk_window_resize ((GtkWindow*) self, 800, 600);
		g_signal_connect ((GtkObject*) self, "destroy", (GCallback) _gtk_main_quit_gtk_object_destroy, NULL);
		vbox = g_object_ref_sink ((GtkVBox*) gtk_vbox_new (FALSE, 0));
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) vbox);
		_tmp1 = NULL;
		menubar = (_tmp1 = gtk_ui_manager_get_widget ((GtkUIManager*) self->priv->ui_manager, "/main_menu"), (_tmp1 == NULL) ? NULL : g_object_ref (_tmp1));
		if (menubar != NULL) {
			/*Obsługa akcji*/
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_new"), "activate", (GCallback) _main_wnd_on_file_new_actived_gtk_action_activate, self, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_open"), "activate", (GCallback) _document_manager_open_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_save"), "activate", (GCallback) _document_manager_save_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_save_as"), "activate", (GCallback) _document_manager_save_as_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_save_all"), "activate", (GCallback) _document_manager_save_all_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_close"), "activate", (GCallback) _document_manager_close_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect (ui_manager_get_action (self->priv->ui_manager, "file_close_all"), "activate", (GCallback) ___lambda2_gtk_action_activate, self);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "file_quit"), "activate", (GCallback) _main_wnd_on_file_quit_actived_gtk_action_activate, self, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_undo"), "activate", (GCallback) _document_manager_undo_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_redo"), "activate", (GCallback) _document_manager_redo_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_cut"), "activate", (GCallback) _document_manager_cut_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_copy"), "activate", (GCallback) _document_manager_copy_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_paste"), "activate", (GCallback) _document_manager_paste_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_delete"), "activate", (GCallback) _document_manager_delete_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "edit_select_all"), "activate", (GCallback) _document_manager_select_all_current_gtk_action_activate, self->priv->document_manager, 0);
			ui_manager_set_sensitive_doc_actions (self->priv->ui_manager, FALSE);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "search_find"), "activate", (GCallback) _document_manager_search_in_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "search_find_next"), "activate", (GCallback) _document_manager_goto_next_found_match_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "search_find_prev"), "activate", (GCallback) _document_manager_goto_prev_found_match_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "search_replace"), "activate", (GCallback) _document_manager_replace_in_current_gtk_action_activate, self->priv->document_manager, 0);
			g_signal_connect_object (ui_manager_get_action (self->priv->ui_manager, "search_goto_line"), "activate", (GCallback) _document_manager_goto_line_current_gtk_action_activate, self->priv->document_manager, 0);
			gtk_box_pack_start ((GtkBox*) vbox, menubar, FALSE, FALSE, (guint) 0);
			gtk_window_add_accel_group ((GtkWindow*) self, gtk_ui_manager_get_accel_group ((GtkUIManager*) self->priv->ui_manager));
		} else {
			GtkMessageDialog* msg;
			msg = g_object_ref_sink ((GtkMessageDialog*) gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Nie moge pobrac menu!", NULL));
			gtk_dialog_run ((GtkDialog*) msg);
			gtk_object_destroy ((GtkObject*) msg);
			(msg == NULL) ? NULL : (msg = (g_object_unref (msg), NULL));
		}
		gtk_box_pack_start_defaults ((GtkBox*) vbox, (GtkWidget*) document_manager_get_instance ());
		g_signal_connect_object ((GtkWidget*) self, "delete-event", (GCallback) _main_wnd_on_delete_event_gtk_widget_delete_event, self, 0);
		(vbox == NULL) ? NULL : (vbox = (g_object_unref (vbox), NULL));
		(menubar == NULL) ? NULL : (menubar = (g_object_unref (menubar), NULL));
	}
	return obj;
}


static void main_wnd_class_init (MainWndClass * klass) {
	main_wnd_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MainWndPrivate));
	G_OBJECT_CLASS (klass)->constructor = main_wnd_constructor;
	G_OBJECT_CLASS (klass)->finalize = main_wnd_finalize;
	MAIN_WND_CLASS (klass)->on_file_new_actived = main_wnd_real_on_file_new_actived;
	MAIN_WND_CLASS (klass)->on_file_quit_actived = main_wnd_real_on_file_quit_actived;
	MAIN_WND_CLASS (klass)->on_delete_event = main_wnd_real_on_delete_event;
}


static void main_wnd_instance_init (MainWnd * self) {
	UIManager* _tmp0;
	self->priv = MAIN_WND_GET_PRIVATE (self);
	self->priv->document_manager = document_manager_get_instance ();
	self->priv->ui_manager = _tmp0 = ui_manager_get_instance ();
	_tmp0 = NULL;
}


static void main_wnd_finalize (GObject* obj) {
	MainWnd * self;
	self = MAIN_WND (obj);
	G_OBJECT_CLASS (main_wnd_parent_class)->finalize (obj);
}


GType main_wnd_get_type (void) {
	static GType main_wnd_type_id = 0;
	if (main_wnd_type_id == 0) {
		static const GTypeInfo g_define_type_info = { sizeof (MainWndClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_wnd_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MainWnd), 0, (GInstanceInitFunc) main_wnd_instance_init, NULL };
		main_wnd_type_id = g_type_register_static (GTK_TYPE_WINDOW, "MainWnd", &g_define_type_info, 0);
	}
	return main_wnd_type_id;
}




